#发送请求
#pip install requests
import requests
from lxml import etree
#发送给谁
url='https://dldl1.nsbuket.cc/xiaoshuo/zhongjidouluo/7.html'########

while True:

    #伪装自己
    headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0'}
    #发送请求
    #请求头是headers
    resp=requests.get(url,headers=headers)########
    resp.encoding='utf-8'
    #响应信息
    #每一章内容
    e=etree.HTML(resp.text)
    #有多个数据,用换行链接到一起
    info='\n'.join(e.xpath('//div[@class="m-post"]/p/text()'))
    title=e.xpath('//h1/text()')[0]#有多个数据
    url=f'https://dldl1.nsbuket.cc/{e.xpath("//tr/td[2]/a/@href")[0]}'########
    # print(info)
    # print(title)
    #保存
    with open("斗罗大陆.txt","a+",encoding="utf-8") as f:
        f.write(title+'\n\n'+info+'\n\n')
    if url=='/xiaoshuo/zhongjidouluo/':
        break
